3D Buttons is a control definition (CDEF) that implements the 3D interface as suggested in develop issue 15. When drawing on a 8-bit (or breater) color device (in a color GrafPort), 3D Buttons draws in grey. 3D Buttons drops to normal 2D drawing for black and white (or less than 8 bits of color).
The source for the 3D Buttons CDEF is broken into
• the main entry function:
3D Buttons CDEF.cp
• classes for 4 button variants:
LGBPushButtons
LGBCheckbox
LGBRadio
LIconButton
• utility functions:
LGBControl
LGBDeviceIterator
UGBDraw
[The "GB" stands for "Grey Buttons," which is what I originally called the project.]
I wrote this function in C++, but without any C++ features that require the C++ runtime engine. The CDEF is smaller and faster without all that overhead.
Every function call into the CDEF comes through the main entry point in 3D Buttons CDEF.cp. Main() switches on the button variation and passes control to the entry point for one of the 4 button variations.
Each button variation has a main entry point that switches on the CDEF message. There are only 4 messages that button CDEFs pay attention to: draw, hit test, and 2 messages to calculate the button region.
Most of the code in each button variation is devoted to drawing the buttons. Drawing functions just save the current drawing environment, then loop through the device list, drawing either color or black and white depending on the device (screen) depth.
Change History
1.0b4—31 July 1994
Bug Fix—save and restore the pen color across draws
Draw 3D buttons on 4-bit devices if those devices are also greyscale, not color.
1.0b3—29 July 1994
Added offscreen GWorld support so the button titles would stop that annoying flashing. Many thanks to one of my users for pointing it out.
1.0b2—20 July 1994 (never released)
Call PenNormal() before starting any draw. Alerts would leave the pensize at (2,2) for the default button, which tended to make OK buttons look awful in color.